package cn.lf.android.lawfirm.distribution.controller;


import android.content.Context;

import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.lf.android.lawfirm.AppConfig;
import cn.lf.android.lawfirm.BaseController;
import cn.lf.android.lawfirm.http.manager.EBCallback;
import cn.lf.android.lawfirm.http.manager.MyOkHttpClient;
import cn.lf.android.lawfirm.utils.DebugLog;
import cn.lf.android.lawfirm.utils.JsonBeans;
import cn.lf.android.lawfirm.utils.SPUtil;

import static android.R.attr.type;

/**
 * 分派案件承办团队
 */
public class DistributionMemberConroller extends BaseController {
    DistributionMemberCallback mDistributionMemberCallback;
    private Context context;

    public DistributionMemberConroller(DistributionMemberCallback callback, Context context) {
        this.mDistributionMemberCallback = callback;
        this.context = context;
    }


    /**
     * @param caseId
     * @param memerID
     * @param type
     * @param roleName
     * @param levelName
     * @param userName
     */
    public void onDistributionMember(String caseId, String memerID, final String type, final String roleName, String levelName, String userName, final int position) {
        showProgressDia(context);
        Map<String, String> params = new HashMap<String, String>();
        SPUtil spUtil = new SPUtil(context);
        params.put("caseId", caseId);
        params.put("memerID", memerID);
        params.put("type", type);
        params.put("roleName", roleName);
        params.put("levelName", levelName);
        params.put("userName", userName);
        DebugLog.e("caseId6==" + caseId);
        DebugLog.e("memerID6==" + memerID);
        DebugLog.e("type6==" + type);
        DebugLog.e("roleName6==" + roleName);
        DebugLog.e("levelName6==" + levelName);
        DebugLog.e("userName6==" + userName);
        new MyOkHttpClient().doPost(AppConfig.LSProjectMember, params,
                new EBCallback() {
                    @Override
                    public void onEBResponse(String response) {
                        DebugLog.e("分派团队==" + response);
                        JSONObject myJsonObject;
                        Boolean isSuc;
                        try {
                            myJsonObject = new JSONObject(response);
                            isSuc = myJsonObject.getBoolean("isSuc");
                            if (isSuc) {
                                mDistributionMemberCallback.onDistributionMemberSuccessed(type, roleName,position);
                            } else {
                                mDistributionMemberCallback
                                        .onDistributionMemberFailed(type, roleName,position);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                        dismissProgressDia();
                    }

                    @Override
                    public void onEBError(String errorMsg) {
                        DebugLog.e("错误6==" + errorMsg);
                        mDistributionMemberCallback.onDistributionMemberFailed(type, roleName,position);
                        dismissProgressDia();
                    }
                }, "Authorization", spUtil.getAccessToken());
    }


    public interface DistributionMemberCallback {
        public void onDistributionMemberSuccessed(String type, String roleName,int position);

        public void onDistributionMemberFailed(String type, String roleName,int position);

    }

}
